package com.cgl.mapper;

import com.cgl.pojo.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentsMapper {
    @Insert("insert into comments(id,userId,articleId,content,createdTime,status) VALUES (#{id},#{userId},#{articleId},#{content},#{createdTime},#{status})")
    Boolean addComments(Comment comment);
    @Select("SELECT comments.id AS id, comments.userId AS userId, user.username AS userName, comments.articleId AS articleId, comments.content AS content, comments.createdTime AS createdTime, comments.status AS status FROM comments JOIN user ON comments.userId = user.id WHERE comments.articleId = #{articleId} ORDER BY comments.createdTime DESC LIMIT #{pageIndex}, #{pageSize}")
    List<Comment> selectAll(String articleId,int pageIndex,int pageSize);
    @Update("update comments set status=#{status} where id=#{id}")
    Boolean updateStatus(String id,String status);
}
